package com.huawei.crm.web.domain;

import com.alibaba.fastjson.JSON;
import lombok.NoArgsConstructor;

/**
 * 返回消息结果
 *
 * @author luohua
 * @date 2021年12月30日17:19:15
 */
@NoArgsConstructor
public class MessageResult extends BaseResult {
    private static final long serialVersionUID = -262485231992559854L;

    public MessageResult(int code, String message) {
        super(code, message);
    }

    public MessageResult code(Integer code) {
        this.setCode(code);
        return this;
    }

    public MessageResult message(String message) {
        this.setMessage(message);
        return this;
    }

    public static MessageResult success() {
        return new MessageResult(ResultCode.SUCCESS.code(), ResultCode.SUCCESS.message());
    }

    public static MessageResult of(ResultCode status) {
        return new MessageResult(status.code(), status.message());
    }

    public static MessageResult of(ResultCode status, String message) {
        return new MessageResult(status.code(), message);
    }

    public static MessageResult error() {
        return new MessageResult(ResultCode.FAILED.code(), ResultCode.FAILED.message());
    }

    public static MessageResult error(String message) {
        return new MessageResult(ResultCode.FAILED.code(), message);
    }

    public static MessageResult error(int code, String message) {
        return new MessageResult(code, message);
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }

}
